package cc.chinagps.gateway.client.packet.down;

import cc.chinagps.gateway.client.packet.BasePacket;
import cc.chinagps.gateway.client.packet.base.PacketAdapter;
import cc.chinagps.gateway.util.CommonUtils;
import cc.chinagps.gateway.util.DateTimeUtil;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import lombok.Data;
import lombok.EqualsAndHashCode;

@EqualsAndHashCode(callSuper = true)
@Data
public class Packet06 extends PacketAdapter {
    String sendTime;
    short serialNo;
    byte status = 0;
    int longitude;
    int latitude;

    public Packet06(BasePacket basePacket) {
        super(basePacket);
    }

    public void decodeBusinessData(byte[] data) throws Exception {
    }

    @Override
    public void decodeBusinessData() throws Exception {
        byte[] data = basePacket.getMsgBody();
        decodeBusinessData(data);
    }

    @Override
    public byte[] encodeBussinessData() throws Exception {
        ByteBuf buf = Unpooled.buffer(16);
        buf.writeBytes(DateTimeUtil.str2DateTime(sendTime));
        buf.writeShort(serialNo);
        buf.writeByte(status);
        buf.writeInt(longitude);
        buf.writeInt(latitude);
        return CommonUtils.getByteArray(buf);
    }
}
